<?php
class TripController extends CI_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->model ( 'trip', '', TRUE );
		$this->load->model ( 'user', '', TRUE );
	}
	function addTripInfo() {
		$name = $_POST ['name'];
		$id_User = $_POST ['id_User'];
		$dateStart = $_POST ['dateStart'];
		$result2 = $this->trip->addTripInfo ( $name, $id_User, $dateStart );
		if ($result2 > 0) {
			print $result2;
		
		// insert thanh cong
		} else {
			print '0';
		
		//loi insert
		}
	
	}
	function updateTrip() {
		$id_Trip = $_POST ['id_Trip'];
		$duration = $_POST ['duration'];
		$this->trip->updateTrip ( $id_Trip, $duration );
	}
	function updateTripTime() {
		$id_Trip = $_POST ['id_Trip'];
		$startDate = $_POST ['startDate'];
		$this->trip->updateTripTime ( $id_Trip, $startDate );
	}
	function addTripDetailHotel() {
		$id_Trip = $_POST ['id_Trip'];
		$day = $_POST ['day'];
		$id_Hotel = $_POST ['id_Hotel'];
		$description = $_POST ['description'];
		$id_TripDetail = $this->trip->addTripDetailHotel ( $id_Trip, $day, $id_Hotel, $description );
		print $id_TripDetail;
	}
	function addTripDetailResEvent() {
		$id_TripDetail = $_POST ['id_TripDetail'];
		$id_Obj = $_POST ['id_Obj'];
		$time = $_POST ['time'];
		$id_Type = $_POST ['id_Type'];
		$id_TripDetailRes = $this->trip->addTripDetailResEvent ( $id_TripDetail, $id_Obj, $time, $id_Type );
		print $id_TripDetailRes;
	}
	function getTrip() {
		$id_User = $_POST ['id_User'];
		$result = $this->trip->getTrip ( $id_User );
		if ($result) {
			print (json_encode ( $result )) ;
		}
	}
	function getTripDetailHotel() {
		$id_Trip = $_POST ['id_Trip'];
		$day = $_POST ['day'];
		$result = $this->trip->getTripDetailHotel ( $id_Trip, $day );
		if ($result)
			print (json_encode ( $result )) ;
	}
	function getTripDetailRes() {
		$id_TripDetail = $_POST ['id_TripDetail'];
		$result = $this->trip->getTripDetailRes ( $id_TripDetail );
		if ($result)
			print (json_encode ( $result )) ;
	}
	function getTripDetailEvent() {
		$id_TripDetail = $_POST ['id_TripDetail'];
		$result = $this->trip->getTripDetailEvent ( $id_TripDetail );
		if ($result)
			print (json_encode ( $result )) ;
	}
	function getTripByHotel() {
		$id_Hotel = $_POST ['id_Hotel'];
		$result = $this->trip->getTripByHotel ( $id_Hotel );
		if ($result)
			print (json_encode ( $result )) ;
	}
	function getTripById() {
		$id_Trip = $_POST ['id_Trip'];
		$result = $this->trip->getTripById ( $id_Trip );
		if ($result)
			print (json_encode ( $result )) ;
	}
	function updateTripDetailHotel() {
		$id_TripDetail = $_POST ['id_TripDetail'];
		$id_Hotel = $_POST ['id_Hotel'];
		$description = $_POST ['description'];
		$this->trip->updateTripDetailHotel ( $id_TripDetail, $id_Hotel, $description );
	
	}
	function updateTripDetailResEvent() {
		$id_TripDetail = $_POST ['id_TripDetail'];
		$id_Obj = $_POST ['id_Obj'];
		$time = $_POST ['time'];
		$id_Type = $_POST ['id_Type'];
		$this->trip->updateTripDetailResEvent ( $id_TripDetail, $id_Obj, $time, $id_Type );
	
	}
	function deleteTripDetail() {
		$id_TripDetail = $_POST ['id_TripDetail'];
		$type = $_POST ['type'];
		$this->trip->deleteTripDetail ( $id_TripDetail, $type );
	}
	function getTripDetailByResEvent() {
		$id_Obj = $_POST ['id_Obj'];
		$type = $_POST ['type'];
		$result = $this->trip->getTripDetailByResEvent($id_Obj, $type);
		if ($result)
			print (json_encode ( $result )) ;
	}
	function getTripByIdTripDetail() {
		$id_TripDetail = $_POST ['id_TripDetail'];
		$result = $this->trip->getTripByIdTripDetail ( $id_TripDetail );
		if ($result)
			print (json_encode ( $result )) ;
	}

}